package com.web.test;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class WebApache {
	public static void main(String[] args) {
		// 初始化线程池  
		ExecutorService pool = Executors.newFixedThreadPool(3);
		try {
			//创建监听端口的 ServerSocket类
			ServerSocket server = new ServerSocket(8080);
			while (true) {
				Socket client = server.accept(); // 开始监听
				String ip = client.getInetAddress().getHostAddress();
				int port = client.getPort();
				System.out.println("client [" + ip + "] ::" + port + ":: --- connected");
				pool.execute(new ClientTask(client)); // 使用线程池处理客户端请求
			}
		} catch (IOException e) {
			throw new RuntimeException("服务器异常终止");
		}
	}

}
